package com.cfc.stage1;

public class MyHashMap {

    private Integer[] bucket;

    private int length;

    public MyHashMap() {
        this(10);
    }

    public MyHashMap(int length) {
        bucket = new Integer[length];
        this.length = length;
    }

    public void put(int key, int value) {
        if (length <= key) {
            Integer[] newArray = new Integer[key + 30];
            System.arraycopy(bucket, 0, newArray, 0, length);
            bucket = newArray;
            length = key + 30;
        }
        bucket[key] = value;
    }

    public int get(int key) {
        if (length > key) {
            Integer value = bucket[key];
            return value == null ? -1 : value;
        }
        return -1;
    }

    public void remove(int key) {
        if (length > key) {
            bucket[key] = null;
        }
    }


    public static void main(String[] args) {
        MyHashMap myHashMap = new MyHashMap();
        myHashMap.put(11, 0);

        int i = myHashMap.get(11);
        int i1 = myHashMap.get(2);
        int i2 = myHashMap.get(3);

        myHashMap.remove(1);
        i = myHashMap.get(1);
        myHashMap.put(1, 1);
        myHashMap.put(2, 2);
    }
}
